﻿using System;
using System.Data.Entity;
using System.Data.EntityModel;
using System.Linq;
using System.Collections.Generic;
using AceSoft.RetailPlus.HRM.MembersModel;

namespace AceSoft.RetailPlus
{
    public class HRMMembersMock
    {
        public HRMMembersMock()
        {
            Members _Members = new Members();

            DbSet<HRMMember> _HRMMembers = _Members.HRMMembers;

            Console.WriteLine("Available HRMMember");
            foreach (HRMMember _HRMMember in _HRMMembers.Include("ContactDetail"))
            {
                Console.WriteLine(" {0} : {1}", _HRMMember.ContactID, _HRMMember.ContactDetail.FirstName);
            }

            Console.WriteLine("Deleting HRMMember");
            foreach (HRMMember _HRMMember in _HRMMembers)
            {
                _HRMMembers.Remove(_HRMMember);
                Console.WriteLine(" ContactDetail: {0} deleted.", _HRMMember.ContactDetail.FirstName);
            }
            _Members.SaveChanges();

            Console.WriteLine("Adding HRMMember");
            ContactModel.Contact _Contact = new ContactModel.Contact();
            List<VIPRewardCard> _VIPRewardCards = _Members.HRMRewardCards.ToList();
            DbSet<ContactModel.ContactDetail> _ContactDetails = _Contact.ContactDetails;

            foreach (ContactModel.ContactDetail _ContactDetail in _ContactDetails)
            {
                _HRMMembers.Add(new HRMMember { ContactID = _ContactDetail.ID, 
                                                RewardCardID = _VIPRewardCards[0].ID, 
                                                RewardType = "HRM"});
                Console.WriteLine(" ContactDetail {0} added.", _ContactDetail.FirstName);
            }
            _Members.SaveChanges();

            Console.WriteLine("Relisting HRMMember");
            foreach (HRMMember _HRMMember in _HRMMembers.Include("ContactDetails"))
            {
                Console.WriteLine(" {0} : {1}", _HRMMember.ContactID, _HRMMember.ContactDetail.FirstName);
            }
        }
    }
}
